/*
 * @Descripttion: file content
 * @Author: liuzhou
 * @Date: 2022-08-02 15:52:37
 * @LastEditors: liuzhou
 * @LastEditTime: 2022-09-29 17:37:13
 */
const {
    iconfont,
} = require('../model/iconfontManageModel');


module.exports = {
    fetchIconfontList: async ctx => {
        const {
            length,
            start
        } = ctx.reqParams.body;
        let data = await iconfont.findAndCountAll({
            order:[['updatedAt', 'DESC']],
            limit: length,
            offset: start,
            where: { invalid: 0 } 
        });
        ctx.body = data;
    },

    addIconfontVersion: async ctx => {
        const {
            fileList,
            product,
            remarks,
            iconfontLink
        } = ctx.reqParams.body;
        
        await iconfont.create({
            fileList,
            product,
            remarks,
            iconfontLink
        });

        ctx.body = 'SUCCESS';
    },

    deleteVersion: async ctx => {
        const { id } = ctx.reqParams.router;
        const data = await iconfont.update({invalid: 1}, {
            where: {
                id,
            }
        });
        if (data <= 0) {
            throw new Error('删除失败');
        }
        ctx.body = 'SUCCESS';
    }
};